package com.dao;

import java.sql.*;


/**
 * 封装 得到连接  关闭所有  增 删  改
 * @author
 *
 */
public class BaseDao {
	//得到连接的方法
	public Connection getConnection(){
		Connection conn=null;
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			try {
				conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/microblog?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8",
						"root", "root");
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return conn;
	}

	//关闭所有对象的方法
	public void closeAll(ResultSet rs,Statement st,Connection conn){
		if(rs != null){
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(st!= null){
			try {
				st.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(conn != null){
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

}
